//
//  xinwenTableViewController.m
//  PASystem
//
//  Created by michael on 16/9/20.
//  Copyright © 2016年 czd. All rights reserved.
//

#import "xinwenTableViewController.h"

@interface xinwenTableViewController ()

@end

@implementation xinwenTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = _string;
    self.tableView.bounces = NO;
    [self reloadata];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)reloadata{
NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSString * pwdId = [[NSUserDefaults standardUserDefaults]objectForKey:@"pwdId"];
    NSString * userHumber = [[NSUserDefaults standardUserDefaults]objectForKey:@"userHumber"];
    
 NSString *json =[NSString stringWithFormat: @"{'action':xwzMch,'service':ZCQService, 'userName':'%@','password':'%@', 'vaueJson':'{userid :%@,id:%@}'}",userId,pwdId,userHumber,_id];
     NSArray * array = @[@{@"arg0":json}];
    [HttpTools requestWithURL:BaseURL arrays:array method:Basemethod success:^(id JSON) {
    
     NSDictionary *dic = JSON[@"reason"];
        NSDictionary *dict = dic[@"attrs"];
       _dic = dict;
    [self.tableView reloadData];
    }
     failure:^(NSError *error) {
        

    }];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row==0) {
 
     UITableViewCell* cell = [[UITableViewCell alloc]init];
          cell.selectionStyle = UITableViewCellSelectionStyleNone;

      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, cell.contentView.height)];
    label.text = @"新闻标题:";
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth-20-100, label.height)];
 
 
//     label2.text = _dic[@"cause"];
label2.textAlignment = NSTextAlignmentRight;
    label2.text = [NSString stringWithFormat:@"%@",_dic[@"TITLE"]];
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;
 
 }
if (indexPath.row==1) {
 
     UITableViewCell* cell = [[UITableViewCell alloc]init];
          cell.selectionStyle = UITableViewCellSelectionStyleNone;

      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, cell.contentView.height)];
    label.text = @"新闻发布时间日期:";
    label.numberOfLines = 0;
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth-20-100, label.height)];
  NSString *string = _dic[@"PUBLISHTIME"];
  NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
    fmt.dateFormat = @"MMM d, yyyy HH:mm:ss aa";
 fmt.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en-US"];
     NSDate *date = [fmt dateFromString:string];
     NSDateFormatter *fm = [[NSDateFormatter alloc] init];
    fm.dateFormat = @"yyyy-MM-dd";
     NSString *selfYear = [fm stringFromDate:date];

 
label2.textAlignment = NSTextAlignmentRight;
    label2.text = selfYear;
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;
 
 }
else {
 
     UITableViewCell* cell = [[UITableViewCell alloc]init];
          cell.selectionStyle = UITableViewCellSelectionStyleNone;

      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, cell.contentView.height)];
    label.text = @"新闻内容:";
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
  NSString *string = _dic[@"CONTENT"];
NSString *result = [string stringByReplacingOccurrencesOfString:@"&quot;" withString:@"\""];

result = [result stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"];
result = [result stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"];


 UIWebView *web= [[UIWebView alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth-20-100,180)];
 web.delegate = self;
 [web loadHTMLString:result baseURL:nil];
 web.backgroundColor = [UIColor whiteColor];
       [cell.contentView addSubview:web];
    return cell;
 
 }

}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{


CGFloat H = 60;
if (indexPath.row ==2){
return 180;
}else{
return H;
}


}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
